//
// Created by francklinson on 2021/10/21 AT 15:00.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    vector<vector<int>> construct2DArray(vector<int> &original, int m, int n) {
        if (m * n != original.size())
            return vector<vector<int>>{};
        vector<vector<int>> ans(m, vector<int>(n, 0));
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                ans[i][j] = original[n * i + j];
            }
        }
        return ans;
    }

    vector<vector<int>> construct2DArray2(vector<int> &original, int m, int n) {
        if (original.size() != m * n) return {};
        vector<vector<int>> A(m, vector<int>(n));
        int L = 0;
        for (auto &v: A) {
            for (auto &x: v) x = original[L++];
        }
        return A;
    }
};

int main() {
    vector<int> original{1, 2, 3, 4};
    Solution solution;
    vector<vector<int>> ans = solution.construct2DArray(original, 2, 2);
    for (auto &row: ans) {
        for (auto &x: row) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}

